﻿using System;
using System.Collections.Generic;
using T.FAS.Runtime.Action.SPI;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Action.Common
{
    public class DefaultTSchemaBuilder : ITSchemaBuilder
    {
        public TSchema ConvertToTSchema<T>(TSchemaConvertType tsType, T data)
        {
            return BuildDemoTSchema(tsType);
        }

        public TSchema ConvertToTSchema(TSchemaConvertType tsType, string metadataID)
        {
            return BuildDemoTSchema(tsType);
        }
        private TSchema BuildDemoTSchema(TSchemaConvertType tsType)
        {
            if (tsType == TSchemaConvertType.EO)
                return BuildDDPMetadataSchema();
            else
                return BuildDepartmentSchema();
        }

        private TSchema BuildDepartmentSchema()
        {
            return new TSchema()
            {
                ActionID = Guid.NewGuid().ToString(),
                ActionCode = "Action.CDO_GetDepartment()",
                ActionName = "Action.CDO_GetDepartment()",
                MetadataType = TEntityType.CDO,
                Entity = new TEntity()
                {
                    MetadataID = Guid.NewGuid().ToString(),
                    MetadataCode = "DO_Department",
                    MetadataName = "DO_Department",
                    Description = "DO_Department",
                    MetadataType = TEntityType.DO,
                    ResultType = DataType.List,
                    Attributes = new List<TAttribute>()
                        {
                            new TAttribute()
                            {
                                ID ="DepartmentID",
                                Code = "ID",
                                Name="主键标识",
                                DataType = DataType.String,
                                Description ="主键标识",
                                SortOrder =0,
                                IsPrimaryKey =true,
                            },
                            new TAttribute()
                            {
                                ID = "DepartmentCode",
                                Code="Code",
                                Name="编号",
                                DataType = DataType.String,
                                Description="编号",
                                SortOrder =1,
                            },
                            new TAttribute()
                            {
                                ID = "DepartmentName",
                                Code="Name",
                                Name="名称",
                                DataType = DataType.String,
                                Description="名称",
                                SortOrder =2,
                            },
                            new TAttribute()
                            {
                                ID = "DepartmentName",
                                Code="CompanyID",
                                Name="所属公司ID",
                                DataType = DataType.String,
                                Description="所属公司ID",
                                SortOrder =3,
                                IsVirtual = true,
                            },
                            new TAttribute()
                            {
                                ID = "Department-Company",
                                Code="Company",
                                Name="公司",
                                DataType = DataType.Record,
                                Description="公司",
                                SortOrder =4,
                                RelatePropertyCode ="CompanyID",
                                Entity = new TEntity()
                                {
                                    Relation = new TEntityRelation()
                                    {
                                        ID = Guid.NewGuid().ToString(),
                                        FromTEntityCode = "DO_Department",
                                        FromTAttributeCode = "CompanyID",
                                        ToTEntityCode = "DO_Company",
                                        ToTAttributeCode = "ID",
                                    },
                                    MetadataID = Guid.NewGuid().ToString(),
                                    MetadataCode = "DO_Company",
                                    MetadataName= "DO_Company",
                                    Description = "DO_Company",
                                    MetadataType = TEntityType.DO,
                                    Attributes = new List<TAttribute>()
                                    {
                                        new TAttribute()
                                        {
                                            ID ="CompanyID",
                                            Code = "ID",
                                            Name="主键标识",
                                            DataType = DataType.String,
                                            Description ="主键标识",
                                            SortOrder =0,
                                            IsPrimaryKey =true,
                                        },
                                        new TAttribute()
                                        {
                                            ID = "CompanyCode",
                                            Code="Code",
                                            Name="编号",
                                            DataType = DataType.String,
                                            Description="编号",
                                            SortOrder =1,
                                        },
                                        new TAttribute()
                                        {
                                            ID = "CompanyName",
                                            Code="Name",
                                            Name="名称",
                                            DataType = DataType.String,
                                            Description="名称",
                                            SortOrder =2,
                                        },
                                    }
                                }
                            },
                            new TAttribute()
                            {
                                ID = "DepartmentCreateTime",
                                Code="CreateTime",
                                Name="创建时间",
                                DataType = DataType.Date,
                                Description="创建时间",
                                SortOrder =4,
                            },
                        }
                }
            };
        }

        private TSchema BuildDDPMetadataSchema()
        {
            return new TSchema()
            {
                ActionID = "7c8c6040-ba9a-4cf4-b1c7-e784ded3ae16",
                ActionCode = "Action.Action_QueryMetaDatasNoAuth()",
                ActionName = "Action.Action_QueryMetaDatasNoAuth()",
                MetadataType = TEntityType.SGEO,
                Entity = new TEntity()
                {
                    MetadataID = Guid.NewGuid().ToString(),
                    MetadataCode = "EO_MetaDataInfo",
                    MetadataName = "EO_MetaDataInfo",
                    Description = "EO_MetaDataInfo",
                    MetadataType = TEntityType.SGEO,
                    ResultType = DataType.List,
                    Attributes = new List<TAttribute>()
                        {
                            new TAttribute()
                            {
                                ID ="ID",
                                Code = "ID",
                                Name="主键标识",
                                DataType = DataType.String,
                                Description ="主键标识",
                                SortOrder =0,
                                IsPrimaryKey =true,
                            },
                            new TAttribute()
                            {
                                ID = "Code",
                                Code="Code",
                                Name="编号",
                                DataType = DataType.String,
                                Description="编号",
                                SortOrder =1,
                            },
                            new TAttribute()
                            {
                                ID = "Name",
                                Code="Name",
                                Name="名称",
                                DataType = DataType.String,
                                Description="名称",
                                SortOrder =2,
                            },
                            new TAttribute()
                            {
                                ID = "MetaTypeID",
                                Code="MetaTypeID",
                                Name="元数据类型ID",
                                DataType = DataType.String,
                                Description="元数据类型ID",
                                SortOrder =3,
                            },
                            new TAttribute()
                            {
                                ID = "MetaTypeName",
                                Code="MetaTypeName",
                                Name="元数据类型名称",
                                DataType = DataType.String,
                                Description="元数据类型名称",
                                SortOrder =4,
                            },
                            new TAttribute()
                            {
                                ID = "MetaSpaceID",
                                Code="MetaSpaceID",
                                Name="元数据控件ID",
                                DataType = DataType.String,
                                Description="元数据控件ID",
                                SortOrder =5,
                            },
                            new TAttribute()
                            {
                                ID = "MetadataStatus",
                                Code="MetadataStatus",
                                Name="元数据状态",
                                DataType = DataType.Int,
                                Description="元数据状态",
                                SortOrder =6,
                            },
                            new TAttribute()
                            {
                                ID = "CheckOutUser",
                                Code="CheckOutUser",
                                Name="签出人",
                                DataType = DataType.String,
                                Description="签出人",
                                SortOrder =7,
                            },
                            new TAttribute()
                            {
                                ID = "Depth",
                                Code="Depth",
                                Name="级次",
                                DataType = DataType.Int,
                                Description="级次",
                                SortOrder =8,
                            },
                            new TAttribute()
                            {
                                ID = "IsDeleted",
                                Code="IsDeleted",
                                Name="是否删除",
                                DataType = DataType.Boolean,
                                Description="是否删除",
                                SortOrder =9,
                            },
                            new TAttribute()
                            {
                                ID = "ContentID",
                                Code="ContentID",
                                Name="元数据内容ID",
                                DataType = DataType.String,
                                Description="元数据内容ID",
                                SortOrder =10,
                            },
                            new TAttribute()
                            {
                                ID = "Content",
                                Code="Content",
                                Name="元数据内容",
                                DataType = DataType.String,
                                Description="元数据内容",
                                SortOrder =11,
                            },
                            new TAttribute()
                            {
                                ID = "Owner",
                                Code="Owner",
                                Name="负责人",
                                DataType = DataType.String,
                                Description="负责人",
                                SortOrder =12,
                            },
                            new TAttribute()
                            {
                                ID = "MetaDataManageInfos",
                                Code="MetaDataManageInfos",
                                Name="元数据管理信息",
                                DataType = DataType.String,
                                Description="元数据管理信息",
                                SortOrder =13,
                            },
                            new TAttribute()
                            {
                                ID = "SortCode",
                                Code="SortCode",
                                Name="顺序号",
                                DataType = DataType.Int,
                                Description="顺序号",
                                SortOrder =14,
                            },
                            new TAttribute()
                            {
                                ID = "GUID",
                                Code="GUID",
                                Name="GUID",
                                DataType = DataType.String,
                                Description="GUID",
                                SortOrder =15,
                            },
                            new TAttribute()
                            {
                                ID = "KeyAppId",
                                Code="KeyAppId",
                                Name="关键应用ID",
                                DataType = DataType.String,
                                Description="关键应用ID",
                                SortOrder =16,
                            },
                            new TAttribute()
                            {
                                ID = "ModuleID",
                                Code="ModuleID",
                                Name="模块ID",
                                DataType = DataType.String,
                                Description="模块ID",
                                SortOrder =17,
                            },
                            new TAttribute()
                            {
                                ID = "FuncID",
                                Code="FuncID",
                                Name="功能ID",
                                DataType = DataType.String,
                                Description="功能ID",
                                SortOrder =18,
                            },
                            new TAttribute()
                            {
                                ID = "Tag",
                                Code="Tag",
                                Name="标签",
                                DataType = DataType.String,
                                Description="标签",
                                SortOrder =19,
                            },
                            new TAttribute()
                            {
                                ID = "Importance",
                                Code="Importance",
                                Name="重要性",
                                DataType = DataType.String,
                                Description="重要性",
                                SortOrder =20,
                            },
                            new TAttribute()
                            {
                                ID = "ServiceSetTypeIDList",
                                Code="ServiceSetTypeIDList",
                                Name="所属服务单元列表信息",
                                DataType = DataType.String,
                                Description="所属服务单元列表信息",
                                SortOrder =21,
                            },
                            new TAttribute()
                            {
                                ID = "CurrentVersionID",
                                Code="CurrentVersionID",
                                Name="当前版本ID",
                                DataType = DataType.String,
                                Description="当前版本ID",
                                SortOrder =22,
                            },
                            new TAttribute()
                            {
                                ID = "CurrentVersion",
                                Code="CurrentVersion",
                                Name="当前版本号",
                                DataType = DataType.String,
                                Description="当前版本号",
                                SortOrder =23,
                            },
                            new TAttribute()
                            {
                                ID = "Ext",
                                Code="Ext",
                                Name="扩展属性",
                                DataType = DataType.String,
                                Description="扩展属性",
                                SortOrder =24,
                            },
                            new TAttribute()
                            {
                                ID = "TenantId",
                                Code="TenantId",
                                Name="租户ID",
                                DataType = DataType.String,
                                Description="租户ID",
                                SortOrder =25,
                            },
                            new TAttribute()
                            {
                                ID = "Ext1",
                                Code="Ext1",
                                Name="扩展字段1",
                                DataType = DataType.String,
                                Description="扩展字段1",
                                SortOrder =26,
                            },
                            new TAttribute()
                            {
                                ID = "Ext2",
                                Code="Ext2",
                                Name="扩展字段2",
                                DataType = DataType.String,
                                Description="扩展字段2",
                                SortOrder =27,
                            },
                            new TAttribute()
                            {
                                ID = "Ext3",
                                Code="Ext3",
                                Name="扩展字段3",
                                DataType = DataType.String,
                                Description="扩展字段3",
                                SortOrder =28,
                            },
                            new TAttribute()
                            {
                                ID = "Creator",
                                Code="Creator",
                                Name="创建人",
                                DataType = DataType.String,
                                Description="创建人",
                                SortOrder =29,
                            },
                            new TAttribute()
                            {
                                ID = "CreateTime",
                                Code="CreateTime",
                                Name="创建时间",
                                DataType = DataType.DateTime,
                                Description="创建时间",
                                SortOrder =30,
                            },
                            new TAttribute()
                            {
                                ID = "LastModifier",
                                Code="LastModifier",
                                Name="最后修改人",
                                DataType = DataType.String,
                                Description="最后修改人",
                                SortOrder =31,
                            },
                            new TAttribute()
                            {
                                ID = "LastModifyTime",
                                Code="LastModifyTime",
                                Name="最后修改时间",
                                DataType = DataType.DateTime,
                                Description="最后修改时间",
                                SortOrder =32,
                            },
                            new TAttribute()
                            {
                                ID = "CreateTimeStr",
                                Code="CreateTimeStr",
                                Name="创建时间显示",
                                DataType = DataType.String,
                                Description="创建时间显示",
                                SortOrder =33,
                            },
                            new TAttribute()
                            {
                                ID = "LastModifyTimeStr",
                                Code="LastModifyTimeStr",
                                Name="最后修改时间显示",
                                DataType = DataType.String,
                                Description="最后修改时间显示",
                                SortOrder =34,
                            },
                        }
                }
            };
        }


    }
}
